/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.interpreter.backends.rete;

import xowl.interpreter.backends.rdf.RDFTripleField;
import xowl.interpreter.backends.rdf.RDFNode;
import xowl.interpreter.backends.rdf.XOWLVariableNode;

/**
 *
 * @author Laurent WOUTERS
 */
public class BetaJoinNodeTest {
    private XOWLVariableNode variable;
    private RDFTripleField field;
    
    public XOWLVariableNode getVariable() { return variable; }
    public RDFTripleField getField() { return field; }
    
    public BetaJoinNodeTest(XOWLVariableNode var, RDFTripleField field) {
        this.variable = var;
        this.field = field;
    }
    
    public boolean check(Token t, TripleFact fact) {
        RDFNode arg1 = t.getBinding(variable);
        RDFNode arg2 = fact.getTriple().getField(field);
        return (arg1 == arg2);
    }

    @Override public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (this.variable != null ? this.variable.hashCode() : 0);
        hash = 37 * hash + (this.field != null ? this.field.hashCode() : 0);
        return hash;
    }

    @Override public boolean equals(Object obj) {
        if (!(obj instanceof BetaJoinNodeTest))
            return false;
        BetaJoinNodeTest test = (BetaJoinNodeTest)obj;
        if (this.variable != test.variable)
            return false;
        return (this.field == test.field);
    }
}
